<?php
//start_material_search
//开始素材搜索，5118会先采集数据
header('Content-Type:text/html;charset=utf8');
require_once __DIR__ . "/../db_orm.php";
require_once __DIR__ . "/../function.php";

use Illuminate\Database\Capsule\Manager as DB;

$db_table1 = 'product';
$db_table2 = 'news';

$res = get_res($db_table1, $db_table2);
//5118配置
$host = "http://apis.5118.com";
$path = "/api/sucai";
$method = "POST";
$apikey = "BF74BDDCF7584279ABE28C0707ECC4D4";
$headers = array();
array_push($headers, "Authorization:" . $apikey);
//根据API的要求，定义相对应的Content-Type
array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
$url = $host . $path;
if (!empty($res)) {
    foreach ($res as $key => $value) {
        $bodys = "keyword=" . $value['name'] . "&page_index=1&page_size=100";
        curl_post($url, $headers, $bodys);
        echo ($key + 1) . '/' . count($res)."\n";
    }
}